import MD5 from 'md5'
import { tokenStorageKey, telphoneStorageKey, userNameStorageKey } from 'common/js/config'
import { getStorage } from 'common/js/utils'

const hostname = location.hostname

export let HttpUrl = ''
export let LoginUrl = ''
export let FileUrl = ''
export let ApiType = ''

// 判断 IP 去改变接口地址
switch (hostname) {
  case '121.237.176.87':
    LoginUrl = `http://218.13.152.128:3000/SsNw/`
    HttpUrl = `http://218.13.152.128:3000`
    FileUrl = `${HttpUrl}/file/upload`
    break
  default:
    LoginUrl = `http://localhost:5174/SsNw/`
    HttpUrl = `http://218.13.152.128:3000`
    FileUrl = `${HttpUrl}/file/upload`
    break
}

// 后台数据返回成功标识
export const ERR_OK = 0

// 登陆超时标识
export const ERR_TIMEOUT = 402

// 访问后台传的token值
export const Options = () => ({
  headers: {
    // 'token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvcHVzTG9naW5Vc2VyIjp7InVzZXIiOnsidXNlcklkIjoiOWMzYjg0MjEtMTI1OS00OTA1LWE0NjgtMmRhZjhkNWE2MDJiIiwidXNlck5hbWUiOiLlirPlhYbln44iLCJsb2dpbk5hbWUiOiJzaGphZG1pbiIsImxvZ2luUHdkIjpudWxsLCJpc0xvY2siOiIwIiwibG9naW5GYWlsTnVtIjowLCJsb2NrVGltZSI6bnVsbCwiaXNBY3RpdmUiOiIxIiwiYWN0aXZlQmVnaW5UaW1lIjpudWxsLCJhY3RpdmVFbmRUaW1lIjpudWxsfSwib3JncyI6W3sib3JnSWQiOiI0MjM0NiIsIm9yZ05hbWUiOiLlupTnlKjns7vnu5_nu4Tnu4cifSx7Im9yZ0lkIjoiNTRmMThiMjYtODdjMC00NzU2LWE2NDctNTFkZTFjNDA1M2EzIiwib3JnTmFtZSI6IuawtOeOr-Wig-W6lOeUqCJ9LHsib3JnSWQiOiIxYWZjZmI4Zi04NWNmLTQ4ZWUtODk3ZS02ZGMyNmExNWU3NmIiLCJvcmdOYW1lIjoi5p625p6E5LiAIn0seyJvcmdJZCI6Ijk0YzYxMzllLTI5YzEtNDIzZS1iYTliLTk4YjQ4NjQzZWViNCIsIm9yZ05hbWUiOiLkvZvlsbHluILmsLTliqHlsYAifSx7Im9yZ0lkIjoiNjJlNTM5NDQtOGQ1YS00ZWY3LWJiMTgtNDVkOTZkMTFjNzVhIiwib3JnTmFtZSI6IuawtOeOr-Wig-ayu-eQhuenkSJ9XSwiY3VycmVudE9yZ0lkIjoiMDM2ODk0OGEtMWNkZi00YmY4LWE4MjgtNzFkNzk2YmE4OWY2IiwiY3VycmVudE9yZ0NvZGUiOiJSMDI5IiwiY3VycmVudFRtbiI6Im9cdTAwMEZia1xmZSIsImFwcFNvZnRDb250ZXh0cyI6W10sInRtbk1lbnVDb250ZXh0cyI6W119LCJpbmRleENvbmZpZ1VybCI6bnVsbCwidXNlcl9uYW1lIjoic2hqYWRtaW4iLCJzY29wZSI6WyJhbGwiXSwiZXhwIjoxNzQwNTczMDY4LCJqdGkiOiIwZWVhYzg1My00YjU3LTRlODUtYWQxMi04MTAzNjI0OWViZTciLCJjbGllbnRfaWQiOiJnenBzLXl0aCIsInB3ZEV4cGlyZWRUaW1lIjoiMjAyNS0wNS0xOSJ9.TDxXWYHZKxxNd4kG-Cj_4GaQxnsuU3lVlZRL2EB-Y0U'
    token: getStorage(tokenStorageKey)
  }
})
// console.log(MD5(`${MD5('12345678910')}@${MD5('Gykj@9527')}`))
export const UserCheck = () => {
  const telphone = getStorage(telphoneStorageKey)
  const username = getStorage(userNameStorageKey)
  
  const token = MD5(`${telphone}@${username}`)

  return token === '7445c1259aabc9e6ae25d3efd5c764d5'
}
